import allure,time
from selenium.webdriver.common.by import By
from page.page_common_steps import PageCommonSteps
from base.base_common import BaseCommon

class PageProductList(PageCommonSteps):
    def __init__(self, driver):
        super().__init__(driver) # 继承公用方法
        # 元素：菜单栏/产品管理
        # self.menu_produ_list = By.XPATH, "//*[@class='ivu-menu-item ivu-menu-item-active ivu-menu-item-selected']"
        # 元素：点击产品列表
        self.menu_produ_list = By.XPATH,"//*[contains(text(), '产品列表')]"
        # 元素：点击新建
        self.new_construction = By.XPATH, "//*[contains(text(), '新建')]"
        # 元素：嵌套iframe元素
        self.switch_page = By.XPATH, "//*[@id='all-menu-iframe']"
        # 元素：点击项目类型/层次/班型下拉框
        self.input_box = By.XPATH, "//input[@class='ivu-select-input']"
        # 元素：选择下拉框内项目类型
        self.project_type1 = By.XPATH, "//li[@class='ivu-select-item']"
        # 元素：选择下拉框内层次
        self. select_level_link = By.XPATH, "//*[@id='app']/div/div/div[2]/div/div[2]/div/div[1]/form/div[2]/div/div/div[2]/ul[2]/li"
        # 元素：选择下拉框内第一个班型
        self.class_type = By.XPATH, "//*[@id='app']/div/div/div[2]/div/div[2]/div/div[1]/form/div[3]/div/div/div[2]/ul[2]/li[1]"
        # 元素：服务周期/标准收费/最低价格输入框
        self.service_period = By.XPATH, "//*[@id='app']/div/div/div[2]/div/div[2]/div/div[1]/form/div[5]/div/div/div[1]/input"
        # 元素：标准收费输入框
        self.standard_charge = By.XPATH, "//*[@id='app']/div/div/div[2]/div/div[2]/div/div[1]/form/div[8]/div[1]/div/div/input"
        # 元素：最低价格输入框
        self.bottom_price = By.XPATH, "//*[@id='app']/div/div/div[2]/div/div[2]/div/div[1]/form/div[8]/div[2]/div/div/input"
        # 元素：保存并继续
        self.save_continue = By.XPATH, "//span[text()='保存并继续']"
        # 元素：课程计划
        self.curriculum_plan = By.XPATH, "//div[text()='课程计划']"
        # 元素：自建产品
        self.sfbuilt_product = By.XPATH, "//*[@class='ivu-tabs-tab' and contains(text(),'自建产品')]"
        # 元素：平台产品
        self.platform_product = By.XPATH, "//*[@class='ivu-tabs-tab' and contains(text(),'自建产品')]/following-sibling::div"
        # 元素：批量上架
        self.shelf_bulk = By.XPATH, "//*[@class='no-border-table ivu-table-wrapper' and @id='SlotTable_1']/../div[1]/button[7]"
        # 元素：批量下架
        self.batch_removal = By.XPATH, "//*[@class='no-border-table ivu-table-wrapper' and @id='SlotTable_1']/../div[1]/button[8]"
        # 元素：批量编辑
        self.bulk_edit = By.XPATH, "//*[@class='no-border-table ivu-table-wrapper' and @id='SlotTable_1']/../div[1]/button[6]"
        # 元素：产品状态
        self.product_status = By.XPATH, "//*[@class='no-border-table ivu-table-wrapper' and @id='SlotTable_1']/../div[1]/div[7]/div[1]/div/span"
        # 元素：待上架
        self.to_listed = By.XPATH, "//*[@class='no-border-table ivu-table-wrapper' and @id='SlotTable_1']/../div[1]/div[7]/div[2]/ul[2]/li[1]"
        # 元素：已上架
        self.already_listed = By.XPATH, "//*[@class='no-border-table ivu-table-wrapper' and @id='SlotTable_1']/../div[1]/div[7]/div[2]/ul[2]/li[2]"
        # 元素：查询
        self.sel_inquiry = By.XPATH,"//*[@class='no-border-table ivu-table-wrapper' and @id='SlotTable_1']/../div[1]/button[1]"
        # 元素：勾选第一个复选框
        self.check_box1 = By.XPATH, "//*[@class='no-border-table ivu-table-wrapper' and @id='SlotTable_1']/div[1]/div[2]/table/tbody/tr[1]/td[1]/div/label/span/input"
        # 元素：勾选第二个复选框
        self.check_box2 = By.XPATH, "//*[@class='no-border-table ivu-table-wrapper' and @id='SlotTable_1']/div[1]/div[2]/table/tbody/tr[2]/td[1]/div/label/span/input"
        # 元素：批量上架成功
        self.shelf_success = By.XPATH, "//*[text()='批量上架成功！']"
        # 元素：批量下架成功
        self.removed_successfully = By.XPATH, "//*[text()='批量下架成功！']"
        # 元素：自建产品-编辑
        self.edit_product = By.XPATH, "//*[@class='no-border-table ivu-table-wrapper'and @id='SlotTable_1']/div[1]/div[4]/div[2]/table/tbody/tr[1]/td[1]/div/div/a[1]"

        # 元素：保存
        self.editor_save = By.XPATH, "//*[@class='bottom-btn-bar-wrap']/button[2]"
        # 元素：取消
        self.editor_cancel = By.XPATH, "//*[@class='bottom-btn-bar-wrap']/button[1]"
        # 元素：保存成功
        self.save_successfully1 = By.XPATH, "//*[text() ='提交成功']"
        # 元素：批量编辑平台产品
        self.platform_batch_pro = By.XPATH, "//*[@class='ivu-btn ivu-btn-default btn']/span[contains(text(),'批量编辑')]"
        # 元素：批量编辑-选择文件
        self.plat_selection_file = By.XPATH, "//div[@class='ivu-message']/../div[6]/div[2]/div/div/div[2]/div[2]/button"
        # 元素：批量编辑-确定
        self.plat_ensure = By.XPATH, "//div[@class='ivu-message']/../div[6]/div[2]/div/div/div[3]/div/button[1]"








    @allure.step(title="操作步骤:批量编辑平台产品")
    def click_product_control(self):
        self.click(self.platform_product)  # 点击平台产品






    @allure.step(title="操作步骤:点击产品管理")
    def click_product_control(self):
        return self.clicks(self.menu_produ_list)

    @allure.step(title="切换iframe")
    def click_switch_to(self):
        self.switch_to(self.switch_page)

    @allure.step(title="操作步骤：点击新建")
    def click_new_construction(self):
        return self.click(self.new_construction)

    @allure.step(title="操作步骤：点击新建")
    def click_save_continue(self):
        return self.click(self.save_continue)

    @allure.step(title="操作步骤:获取课程计划文本")
    def get_curriculum_plan(self):
        return self.getTextContent(self.curriculum_plan)

    @allure.step(title="操作步骤：选择项目类型")
    def create_product(self):
        self.find_els(self.input_box)[0].click()  # 点击项目类型下拉框
        self.find_els(self.project_type1)[0].click()    # 选择项目类型下拉框的第一个
        self.find_els(self.input_box)[1].click()  # 点击层次下拉框
        self.find_el(self.select_level_link).click()  # 选择层次下拉框的第一个
        self.find_els(self.input_box)[2].click()  # 点击班型下拉框
        self.find_el(self.class_type).click()  # 选择班型下拉框的第一个班型
        self.input(self.service_period, 5)  # 输入服务周期
        self.input(self.standard_charge, 100)  # 输入标准收费
        self.input(self.bottom_price, 100)  # 输入最低价格
        self.click_save_continue()  # 点击保存并继续


    @allure.step(title="操作步骤:自建产品-批量上架")
    def click_shelf_bulk(self):
        self.click(self.product_status)  # 点击产品状态筛选框
        time.sleep(1)
        self.click(self.to_listed)  # 选择状态为待上架
        time.sleep(1)
        self.click(self.sel_inquiry)    # 点击查询
        self.click(self.check_box1)  # 勾选第一个复选框
        self.click(self.check_box2)  # 勾选第二个复选框
        self.click(self.shelf_bulk)  # 批量上架

    @allure.step(title="操作步骤:获取批量上架成功")
    def get_shelf_success(self):
        return self.find_el(self.shelf_success).text  # 批量上架成功

    @allure.step(title="操作步骤:自建产品-批量下架")
    def click_removed_product(self):
        self.click(self.product_status)  # 点击产品状态筛选框
        time.sleep(1)
        self.click(self.already_listed)  # 选择状态为已上架
        time.sleep(1)
        self.click(self.sel_inquiry)    # 点击查询
        self.click(self.check_box1)  # 勾选第一个复选框
        self.click(self.check_box2)  # 勾选第二个复选框
        self.click(self.batch_removal)  # 批量下架

    @allure.step(title="操作步骤:获取批量下架成功")
    def get_removed_successfully(self):
        return self.find_el(self.removed_successfully).text  # 批量下架成功



    @allure.step(title="操作步骤:查询查产品并编辑")
    def click_search_product(self):
        time.sleep(1)
        self.click(self.product_status)  # 点击产品状态筛选框
        time.sleep(1)
        self.click(self.to_listed)  # 选择状态为待上架
        time.sleep(1)
        self.click(self.sel_inquiry)    # 点击查询
        self.click(self.edit_product)   # 点击编辑产品

    @allure.step(title="操作步骤:编辑产品流程")
    def click_editor_produc(self, input_box, service_period, standard_price, minprice):
        time.sleep(1)
        input_content = By.XPATH, "//*[contains(text(),'{0}:')]/../div/div/input".format(input_box)  # 输入服务周期/标准收费/最低价格
        if input_box == '服务周期':
            self.clear(input_content)
            time.sleep(1)
            self.input(input_content, service_period)   # 输入服务周期
        elif input_box == '标准收费':
            self.clear(input_content)
            self.input(input_content, standard_price)   # 输入标准收费
        else:
            self.clear(input_content)
            self.input(input_content, minprice)  # 输入最低价格

    @allure.step(title="操作步骤:获取提交成功")
    def click_editor_save(self):
        return self.click(self.editor_save)   # 点击保存

    @allure.step(title="操作步骤:获取提交成功")
    def get_save_successfully1(self):
        return self.find_el(self.save_successfully1).text  # 获取提交成功

    @allure.step(title="操作步骤:取消返回列表页")
    def click_editor_cancel(self):
        return self.click(self.editor_cancel)  # 取消返回列表页










